home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / misc / math / libalgo.lha / algomath / src / isprime.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-30  |  430 b   |  34 lines

  1. /* do we have a prime number ? */
  2.  
  3. #include "defs.h"
  4.  
  5. int am_isprime(int t)
  6. {
  7.  
  8. #ifdef USE_ISPRIME_ASM
  9.     if(t<0)
  10.         t = -t;
  11.     return am_isPrime(t);
  12. #else
  13.  
  14.      int x=1;
  15.  
  16.     if(t<0)
  17.         t = -t;
  18.  
  19.     if(t>2){
  20.      if (!(t&1))
  21.          return 0;
  22.     while (_am_pp_init[x]<=t)
  23.           {
  24.            if (t%_am_primearray_init[x]==0)
  25.                return 0;
  26.            x++;
  27.           }
  28.        return 1;
  29.     }
  30.     if (t==2)
  31.         return 1;
  32.     return 0;
  33. #endif
  34. }